/**
 * Created by asus on 2017/3/7.
 */
define(['jquery','template','util','jquerycookie','jquerytoTop'],function($,template,util,undefine,undefine){
    var bigTitle= localStorage.getItem('bigtitle');
    console.log(bigTitle);
    $('.allClass').html(bigTitle+'<span class="glyphicon glyphicon-menu-right"></span>');
    var totalCount;
    var pageSize=10;
    var pageArr=[];
    var categoryId=util.getQueryString('categoryid');
    var pageId=util.getQueryString('pageid')||1;
    console.log(categoryId+' '+pageId)

    //console.log(categoryId)
    function init(){
        $.ajax({
            url:'http://139.199.157.195:9090/api/getproductlist',
            type:'get',
            data:{categoryid:categoryId,
                pageid:pageId
            },
            success:function(data){
                totalCount=data.totalCount;
                var len=Math.ceil(totalCount/pageSize);
                for(var i=0;i<len;i++){

                    pageArr.push({
                        categoryid:categoryId,
                        pageid:i+1

                    });
                }
                //console.log(pageArr);
                $('#mulu').html(template('mulutemp',{pagelist:pageArr}));
                $('#shopList').html(template('productList',{list:data.result}));

            }

        });
    }
    init();
    $('.page b').on('click',function(e){
    
        $('#mulu').slideToggle();
     
    });
    //$('.downarrow').html("第"+(pageId)+"页"+'<b class="glyphicon glyphicon-triangle-bottom"></b>');
    $('.pageUp').on('click',function(){
        if(pageId>0){
            pageId--;
            location.href='./shopperClass.html?categoryid='+categoryId+'&pageid='+pageId;
        }

        //console.log(pageId);
    })
    $('.pageDown').on('click',function(){
        if(pageId<4){
            pageId++;
            location.href='./shopperClass.html?categoryid='+categoryId+'&pageid='+pageId;
        }

    });
    $('#shopList').on('click','li',function(){
        //console.log('ss');
        //console.log($(this).attr('li-href'));
        location.href=$(this).attr('li-href');
    });
    $.ajax({
        url:'http://139.199.157.195:9090/api/getcategorybyid',
        type:'get',
        data:{categoryid:categoryId},
        success:function(data){
            //console.log(data.result[0]);
            localStorage.setItem('fenlei',data.result[0]['category'],{path:'../../index.html'});//
            $('.fenlei').html(localStorage.getItem('fenlei')+'<span class="glyphicon glyphicon-menu-right"></span>');
        }
    });
    $('.allClass').on('click',function(){
        location.href='./category.html';
    });
    $('.index').on('click',function(){
        location.href='../../index.html';
    });
    $('.totoop').toTop();
})